<?php
/**
 * @file
 * Process theme data: Twitter Bootstrap Stuff.
 *
 */


/**
 * Implements hook_css_alter().
 * api-ref: https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_css_alter/7
 * $css: an array with all css-files, sorted by groups (SYSTEM, CSS_THEME, ...)
 */
function dsatbootstrap_css_alter( &$css ) {
	$theme_path = drupal_get_path( 'theme', 'dshive_subtheme' );
	
	// add twitter bootstrap CDN files.
	$cdn = '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css';
	
	$css[$cdn] = array(
		'data' => $cdn,
		'type' => 'external',
		'every_page' => TRUE,
		'media' => 'all',
		'preprocess' => TRUE,
		'group' => CSS_THEME,
		'browsers' => array( 'IE' => TRUE, '!IE' => TRUE ),
		'weight' => 2,
	);
	
	
	// add overrides from (drupal)theme "bootstrap".
	$override = $theme_path . 'at_extend/bootstrap-bridge/overrides.css';
	
	$css[$override] = array(
		'data' => $override,
		'type' => 'file',
		'every_page' => TRUE,
		'media' => 'all',
		'preprocess' => TRUE,
		'group' => CSS_THEME,
		'browsers' => array( 'IE' => TRUE, '!IE' => TRUE ),
		'weight' => -1,
	);
	
	// manual excludes are handled by at_core theme, see
	// at_core/inc/alter.inc, line 178ff "adaptivetheme_css_alter()".
	// add "unset_css[path-to-css-file]" in .info file.
	
	
	
	
	// automatically remove all other css files (other than group CSS_THEME).
	// this excludes even css from admin menu. don't use it.
	/*
	foreach( $css as $key => $value ) {
		if( $value['group'] != CSS_THEME ) {
			$exclude[$key] = FALSE;
		}
	}
	$css = array_diff_key( $css, $exclude );
	*/


	#print "<pre>"; print_r( $css ); print "</pre>";
}




/**
 * Implements hook_js_alter().
 */
function dsatbootstrap_js_alter(&$javascript) {
	$theme_path = drupal_get_path( 'theme', 'dshive' );
	
	// add twitter-bootstrap js via cdn.
	$twitter_bootstrap_js = '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js';
	
	$javascript[$twitter_bootstrap_js] = array(
		'data' => $twitter_bootstrap_js,
		'type' => 'external',
		'every_page' => TRUE,
		'weight' => 500,
		'scope' => 'header',
		'cache' => TRUE,
		'group' => 'AT-EXTEND',
		'defer' => TRUE,
		'preprocess' => TRUE,
	);
	
	
	// add baseline.js to the theme. (alignment of img in line-height).
	$baseline_js = $theme_path . '/at_extend/baseline.js/jquery.baseline.js';
	
	$javascript[$baseline_js] = array(
		'data' => $baseline_js,
		'type' => 'file',
		'every_page' => TRUE,
		'weight' => 501,
		'scope' => 'header',
		'cache' => TRUE,
		'group' => 'AT-EXTEND',
		'defer' => TRUE,
		'preprocess' => TRUE,
	);
	
	
	// add settings/control js for extensions.
	$at_extend_js = $theme_path . '/at_extend/at_extend.js';
	
	$javascript[$at_extend_js] = array(
		'data' => $at_extend_js,
		'type' => 'file',
		'every_page' => TRUE,
		'weight' => 502,
		'scope' => 'header',
		'cache' => TRUE,
		'group' => 'AT-EXTEND',
		'defer' => TRUE,
		'preprocess' => TRUE,
	);


	
	#print "<pre>"; print_r( $javascript ); print "</pre>";
}
